function ruleMax() {

}

String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
};

function getKey(key) {
    var title = "C00" + key;
    switch (key) {
        case "0" :
            title = "C001";
            break;
        case "1" :
            title = "C002";
            break;
        case "2" :
            title = "C003";
            break;
        case "3" :
            title = "C005";
            break;
        case "4" :
            title = "C006";
            break;

    }
    return title;
}

function bubbleSort(arr) {
    var len = arr.length;
    for (var i = 0; i < len - 1; i++) {
        for (var j = 0; j < len - 1 - i; j++) {
            var data1 = arr[j].split(":")[1];
            var data2 = arr[j + 1].split(":")[1];
            if (data1 < data2) {        // 相邻元素两两对比
                var temp = arr[j + 1];        // 元素交换
                arr[j + 1] = arr[j];
                arr[j] = temp;
            }
        }
    }
    return arr;
}

/*
* 数据处理流程
* */
function dataDeal(json) {
    console.log(json);
    $('#agResult').html();
    //groupDeal(json)
    /* var json = eval("(" + json + ")");
     var groupHtml = "";
     var map = {};
     for (var key in json) {
         var data = json[key];//[]
         data = data.substring(1, data.length - 1).replaceAll("\"", "");
         var arr = data.split(',');
         var dantiaoNum = dantiao(arr);
         var changlongNum = changlong(arr);
         if(dantiaoNum!=0)map[getKey(key) + "单跳"] = dantiaoNum;
         if(changlongNum!=0)map[getKey(key) + "长龙"] = changlongNum;
         var arr = [];
         for (var key in map) {
             arr.push(key + ":" + map[key]);
         }
         bubbleSort(arr);
         $('#order').html(JSON.stringify(arr));
     }*/

}

/*
* 从服务器获取数据
* */
function getAgData() {
    var r = Math.random();
    $.ajax({
        // url: 'http://www.buziman.com:8080/test/get?r=' + r,
        url: 'http://localhost:8080/test/get?r=' + r,
        type: 'GET',
        dataType: 'TEXT',//'json',TEXT
        success: function (json) {
            dataDeal(json);
        },
        error: function () {
            $('<span>').text(' 服务不可用').insertAfter('#username');
        }
    });
}

setInterval(getAgData, 1000);